package com.ygy.utils;

import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

@Service
public class OrderNumberGenerator {

    private static final String DATE_FORMAT = "yyyyMMddHHmmssSSS";
    private static final AtomicLong counter = new AtomicLong(0);

    public String generateOrderNumber() {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        String datePart = sdf.format(new Date());
        long sequence = counter.incrementAndGet();
        return datePart + String.format("%06d", sequence);
    }
}